# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgbase=pyside6
pkgname=(shiboken6 pyside6 pyside6-tools)
_qtver=6.5.0
_clangver=15.0.7
pkgver=${_qtver/-/}
pkgrel=2
arch=(x86_64)
url='https://www.qt.io'
license=(LGPL)
makedepends=(cmake ninja clang llvm python-setuptools vulkan-headers python-numpy
             qt6-tools qt6-svg qt6-3d qt6-scxml qt6-datavis3d qt6-charts qt6-multimedia qt6-quick3d
             qt6-location qt6-positioning qt6-networkauth qt6-remoteobjects qt6-sensors qt6-serialbus qt6-serialport
             qt6-connectivity qt6-webchannel qt6-webengine qt6-websockets qt6-shadertools qt6-speech qt6-httpserver)
_pkgfn=pyside-setup-everywhere-src-$_qtver
source=(https://download.qt.io/official_releases/QtForPython/pyside6/PySide6-$pkgver-src/${_pkgfn}.tar.xz
        designer-plugin-install-dir.patch)
sha256sums=('6ef53b29127267e381917e6f9399ce760edc0644cd5831988b1de72c9d583ab4'
            '66e895e07d5b01c64a94092353854c946fd7fc445b6181068dca290b5a3887e0')
_pkgfn=${_pkgfn%.*}

prepare() {
  patch -d $_pkgfn -p1 < designer-plugin-install-dir.patch # Fix designer plugin install dir
}

build() {
  cmake -B build -S $_pkgfn -G Ninja \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DBUILD_TESTS=OFF \
    -DNO_QT_TOOLS=yes
  PYTHONPATH="$PWD"/build/sources \
  cmake --build build
}

package_shiboken6() {
  pkgdesc='Generates bindings for C++ libraries using CPython source code'
  depends=(clang=$_clangver llvm libxslt qt6-base)
  optdepends=('python: Python bindings')

  DESTDIR="$pkgdir" cmake --install build/sources/shiboken6

# Install egg-info
  export PATH="/usr/lib/qt6/bin:$PATH"
  export SETUPTOOLS_USE_DISTUTILS=stdlib
  cd $_pkgfn
  python setup.py egg_info --build-type=shiboken6
  python setup.py egg_info --build-type=shiboken6-generator
  _pythonpath=`python -c "from sysconfig import get_path; print(get_path('platlib'))"`
  cp -r shiboken6*.egg-info "$pkgdir"/$_pythonpath
}

package_pyside6() {
  pkgdesc='Enables the use of Qt6 APIs in Python applications'
  depends=(qt6-declarative shiboken6)
  optdepends=('qt6-tools: QtHelp, QtUiTools bindings'
              'qt6-svg: QtSvg bindings'
              'qt6-3d: Qt3D bindings'
              'qt6-quick3d: QtQuick3D bindings'
              'qt6-scxml: QtScxml bindings'
              'qt6-datavis3d: QtDataVisualization bindings'
              'qt6-charts: QtCharts bindings'
              'qt6-httpserver: QtHttpServer bindings'
              'qt6-location: QtLocation bindings'
              'qt6-multimedia: QtMultimedia bindings'
              'qt6-serialbus: QtSerialBus bindings'
              'qt6-serialport: QtSerialPort bindings'
              'qt6-speech: QtTextToSpeech bindings'
              'qt6-webengine: QtWebEngine bindings'
              'qt6-remoteobjects: QtRemoteObjects bindings'
              'qt6-sensors: QtSensors bindings'
              'qt6-websockets: QtWebSockets bindings'
              'qt6-networkauth: QtNetworkAuth bindings')

  DESTDIR="$pkgdir" cmake --install build/sources/pyside6

# Install egg-info
  export PATH="/usr/lib/qt6/bin:$PATH"
  cd $_pkgfn
  python setup.py egg_info --build-type=pyside6
  _pythonpath=`python -c "from sysconfig import get_path; print(get_path('platlib'))"`
  cp -r PySide6.egg-info "$pkgdir"/$_pythonpath

# Install pyi files
  install -Dm644 "$srcdir"/build/sources/pyside6/PySide6/*.pyi -t "$pkgdir"/usr/lib/python*/site-packages/PySide6
}

package_pyside6-tools() {
  pkgdesc='Tools for pyside6'
  depends=(pyside6)

  DESTDIR="$pkgdir" cmake --install build/sources/pyside-tools
}
